package com.dlnu.shoping.shopping.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.dlnu.shoping.shopping.common.Result;
import com.dlnu.shoping.shopping.entity.Address;
import com.dlnu.shoping.shopping.mapper.AddressDao;
import com.dlnu.shoping.shopping.service.IAddressService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class IAddressServiceImpl implements IAddressService {
    @Resource
    private AddressDao addressDao;

    @Override
    public Result search(int useId) {
        List list = addressDao.search(useId);
        return new Result(list);
    }

    @Override
    public Result queryList() {
        return new Result(addressDao.selectList(null));
    }

    @Override
    public Result add(Integer useId, String address, String phone) {
        Address addr = new Address();
        addr.setUseId(useId);
        addr.setAddress(address);
        addr.setPhone(phone);
        addressDao.insert(addr);
        return Result.SUCCESS;
    }

    @Override
    public Result update(Integer addressId, String address, String phone) {
        Address addr = addressDao.selectById(addressId);
        addr.setAddress(address);
        addr.setPhone(phone);
        addressDao.updateById(addr);
        return Result.SUCCESS;
    }

    @Override
    public Result delete(Integer addressId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.like("address_id",addressId);
        addressDao.delete(wrapper);
        return Result.SUCCESS;
    }


}
